
# -*- coding:utf-8 -*-
"""
@file: logger.py
@Description: 显示配置日志
@author: Yu Wenjie
@email : yuwenjie@cetc-cloud.com
@version: 
@date: 2017/10/17 18:59
"""
import logging

#创建日志记录器
logger_name="example"
logger=logging.getLogger(logger_name)
logger.setLevel(logging.WARN)

#创建一个文件处理器
log_path = "./log.log"
fh=logging.FileHandler(log_path)
fh.setLevel(logging.WARN)

#创建格式化器
fmt = "%(asctime)-15s %(levelname)s %(filename)s %(lineno)d %(process)d :%(message)s"
# Tue 17 Oct 2017 19:04:34 WARNING logger.py 35 7144 warn message
datefmt = "%a %d %b %Y %H:%M:%S"
formatter = logging.Formatter(fmt, datefmt)

# add handler and formatter to logger
fh.setFormatter(formatter)
logger.addHandler(fh)

# print log info
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')
